commonlibsse_ng\rel\id/
variant_id.rs

1use core::num::NonZeroUsize;
2
3use crate::rel::{ResolvableAddress, id::id_database::DataBaseError};
4
5/// Represents an ID with a possible VR-specific offset.
6#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
7pub struct VariantID {
8    se_id: u64,
9    ae_id: u64,
10    vr_offset: u64,
11}
12
13impl VariantID {
14    /// Creates a new VariantID instance.
15    #[inline]
16    pub const fn new(se_id: u64, ae_id: u64, vr_offset: u64) -> Self {
17        Self { se_id, ae_id, vr_offset }
18    }
19}
20
21impl ResolvableAddress for VariantID {
22    fn offset(&self) -> Result<NonZeroUsize, DataBaseError> {
23        use crate::rel::id::id_database::ID_DATABASE;
24        use crate::rel::module::{ModuleState, Runtime};
25
26        let runtime = ModuleState::map_or_init(|module| module.runtime)?;
27        let id = match runtime {
28            Runtime::Ae => self.ae_id,
29            Runtime::Se => self.se_id,
30            Runtime::Vr => self.vr_offset,
31        };
32
33        ID_DATABASE.id_to_offset(id)
34    }
35}